package ccm.common;

import java.io.UnsupportedEncodingException;

public final class Buffer
{
    static
    {
        NativeUtils.loadLibrary("libccm_common_Buffer");
    }

    private Buffer()
    {
    }

    public static String getString(int[] buf,int i,int l)
    {
        StringBuilder stringBuilder=new StringBuilder();
        for(int j=0;j<l;++j)
        {
            stringBuilder.append((char)getUint8(buf,i+j));
        }
        return stringBuilder.toString();
    }

    public static String getString(byte[] buf,int i,int l)
    {
        StringBuilder stringBuilder=new StringBuilder();
        for(int j=0;j<l;++j)
        {
            stringBuilder.append((char)getUint8(buf,i+j));
        }
        return stringBuilder.toString();
    }

    public static String getString(byte[] buf,int i,int l,String decode,String encode) throws UnsupportedEncodingException
    {
        return new String(getString(buf,i,l).getBytes(decode),encode);
    }

    public static String getString(int[] buf,int i,int l,String decode,String encode) throws UnsupportedEncodingException
    {
        return new String(getString(buf,i,l).getBytes(decode),encode);
    }

    native public static short getUint8(int[] buf,int i);

    native public static short getUint8(byte[] buf,int i);

    native public static int getUint16(int[] buf,int i);

    native public static int getUint16(byte[] buf,int i);

    native public static int getUint24(int[] buf,int i);

    native public static int getUint24(byte[] buf,int i);

    native public static long getUint32(int[] buf,int i);

    native public static long getUint32(byte[] buf,int i);

    native public static long getUint64(int[] buf,int i);

    native public static long getUint64(byte[] buf,int i);

    native public static short getInt8(int[] buf,int i);

    native public static short getInt8(byte[] buf,int i);

    native public static short getInt16(int[] buf,int i);

    native public static short getInt16(byte[] buf,int i);

    native public static int getInt32(int[] buf,int i);

    native public static int getInt32(byte[] buf,int i);

    native public static long getInt64(int[] buf,int i);

    native public static long getInt64(byte[] buf,int i);

    native public static float getFloat16(int[] buf,int i);

    native public static float getFloat16(byte[] buf,int i);


    native public static float getFloat24(int[] buf,int i);

    native public static float getFloat24(byte[] buf,int i);


    native public static float getFloat(int[] buf,int i);

    native public static float getFloat(byte[] buf,int i);

    native public static double getDouble(int[] buf,int i);

    native public static double getDouble(byte[] buf,int i);


    native public static int setUint8(int[] buf,int i,short d);

    native public static int setUint8(byte[] buf,int i,short d);

    public static int setUint8(int[] buf,int i,int d)
    {
        return setUint8(buf,i,(short)d);
    }

    public static int setUint8(byte[] buf,int i,int d)
    {
        return setUint8(buf,i,(short)d);
    }

    native public static int setUint16(int[] buf,int i,int d);

    native public static int setUint16(byte[] buf,int i,int d);

    native public static int setUint24(int[] buf,int i,int d);


    native public static int setUint24(byte[] buf,int i,int d);


    native public static int setUint32(int[] buf,int i,long d);


    native public static int setUint32(byte[] buf,int i,long d);


    native public static int setUint64(int[] buf,int i,long d);


    native public static int setUint64(byte[] buf,int i,long d);


    native public static int setInt8(int[] buf,int i,short d);


    native public static int setInt8(byte[] buf,int i,short d);

    native public static int setInt16(int[] buf,int i,short d);


    native public static int setInt16(byte[] buf,int i,short d);


    native public static int setInt32(int[] buf,int i,int d);

    native public static int setInt32(byte[] buf,int i,int d);


    native public static int setInt64(int[] buf,int i,long d);

    native public static int setInt64(byte[] buf,int i,long d);


    native public static int setFloat16(int[] buf,int i,float f);

    native public static int setFloat16(byte[] buf,int i,float f);

    native public static int setFloat24(int[] buf,int i,float f);

    native public static int setFloat24(byte[] buf,int i,float f);

    native public static int setFloat(int[] buf,int i,float f);


    native public static int setFloat(byte[] buf,int i,float f);

    native public static int setDouble(int[] buf,int i,double f);


    native public static int setDouble(byte[] buf,int i,double f);
}
